{extend name="$_mill_base_layout" /}

{block name="content"}

{// 主体内容}
<div class="bottom">
    {// 主体内容}
    <div class="bottomBox s_center">

        {// 显示多个列表 dump($table_lists);}
        {if(isset($table_lists))}
        {php}$table_list_i = 0;{/php}
        {volist name="table_lists" id="table_list"}
        {empty name="table_list['online_hide']"}
        {php}$table_list_i ++;{/php}
        <div class="right table-list" data-id="{$table_list['id']}" data-title="{$table_list['title']}" data-url = "{$table_list['url_value']}">
            <input type="hidden" id="_map{$table_list['id']}" value="">
            <input type="hidden" id="_page{$table_list['id']}" value="">
            <input type="hidden" id="_o{$table_list['id']}" value="{$_search_area_op|default=''}">

            <!--标题-->
            <div class="s_title s_center" action="{$table_list['url_value']}">
                <!--标题-->
                <div class="flex flex-center flex-center-left">
                    <div class="name table-title">{// $table_list['title']}</div>
                    <div class="flex flex-center form-left"></div>
                </div>
                <!--顶部按钮-->
                <div class="up top-buttons flex-center-right" id="toolbar{$table_list['id']}"></div>
            </div>

            <!--左侧菜单-->
            {php}$hide_nav_left = false;{/php}
            {notempty name="tab_nav"}
            {php}$hide_nav_left = true;{/php}
            <div class="s_nav-old" style="display: none" >
                <div class="layui-side">
                    <ul class="layui-nav layui-nav-tree">

                        {volist name="tab_nav['tab_list']" id="tab"}

                        <li class="layui-nav-item layui-nav-itemed {eq name="tab_nav.curr_tab" value="$key"}layui-this{/eq}">

                            {notempty name="tab['child']"}
                            <a class="item-border" ><div class="nav-li-a">{$tab.title|htmlspecialchars}</div></a>
                            <?php $_pop2=1;$_tab_id=$key;?>
                            <dl class="layui-nav-child">
                                {volist name="tab['child']" id="tab2"}
                                <dd class="layui-nav-item {eq name="tab_nav.curr_tab" value="$key"}on{/eq}">
                                    <a href="{$tab2.url_value}{$_pop ?= '?_pop=1'}" target="{$tab2.url_target}"><i class="{$tab2.icon|htmlspecialchars}"></i>{$tab2.title|htmlspecialchars}</a>
                                </dd>
                                {/volist}
                            </dl>
                            {else /}
                            <a class="item-border" href="{$tab.url_value}{$_pop ?= '?_pop=1'}" target="{$tab.url_target}"><div class="nav-li-a">{$tab.title|htmlspecialchars}</div></a>
                            {/notempty}
                            <!--<dl class="layui-nav-child">-->
                                <!--<dd class="layui-nav-item"><a><i class="iconfont mill-youqi"></i>油漆</a></dd>-->
                                <!--<dd class="layui-nav-item"><a><i class="iconfont mill-fenmo"></i>粉末</a></dd>-->
                                <!--<dd class="layui-nav-item"><a><i class=""></i>转印纸</a></dd>-->
                                <!--<dd class="layui-nav-item"><a><i class=""></i>铝卷</a></dd>-->
                                <!--<dd class="layui-nav-item"><a><i class=""></i>板材</a></dd>-->
                                <!--<dd class="layui-nav-item"><a><i class=""></i>型材</a></dd>-->
                                <!--<dd class="layui-nav-item"><a><i class=""></i>化工</a></dd>-->
                                <!--<dd class="layui-nav-item"><a><i class=""></i>生产物资</a></dd>-->
                                <!--<dd class="layui-nav-item"><a><i class=""></i>办公物资</a></dd>-->
                            <!--</dl>-->
                        </li>

                        {/volist}

                    </ul>
                </div>

            </div>
            {/notempty}


            <div class="s_table" {if($hide_nav_left && $table_list_i == 1)}style="float: right;width: calc(100% - 150px);"{/if}>

                <!--选项卡-->
                {notempty name="tab_nav2"}
                <div class="layui-tab layui-tab-brief">
                    <ul class="layui-tab-title">

                        {volist name="tab_nav2['tab_list']" id="tab2"}

                        <li class="{eq name="tab_nav2.curr_tab" value="$key"}layui-this{/eq}">
                            <a href="{$tab2.url_value}{$_pop ?= '?_pop=1'}">{$tab2.title|htmlspecialchars}</a>
                        </li>
                        {/volist}
                    </ul>
                </div>
                {/notempty}
                <!--搜索-->
                <form class="title s_center" action="{$table_list['url_value']}">
                    <!--搜索-->
                    <!--<div class="flex flex-center flex-center-right"></div>-->
                    <div class="form-right" style="display: ruby"></div>
                </form>

                <div class="table">
                    <!--列表-->
                    <div class="tableBox ">
                        <table id="table{$table_list['id']}" lay-filter="table{$table_list['id']}"></table>
                        <!--分页-->
                        <div class="layui-table-column layui-table-page" id="table-page{$table_list['id']}"></div>
                    </div>
                </div>

                <!--额外JS代码-->
                <div class="extra_js" style="display: none"></div>
            </div>

        </div>

        {/empty}
        {/volist}
        {/if}
    </div>

</div>

{/block}

{block name="style"}
{volist name="css_list" id="vo"}
<link rel="stylesheet" href="{$vo}?v={:config('asset_version')}">
{/volist}

{// 额外CSS代码 }
{$extra_css|raw|default=''}
{/block}

{block name="script"}
<script>

    // 提交表单
    $('#search-area').submit(function () {
        $.each($(this).find('input'), function () {
            if($(this).val().indexOf("#") >= 0)$(this).val(encodeURIComponent($(this).val()));
        });
    });

    $(document).ready(function () {
        //删除layui样式
        $('.layui-form-select').remove();
        //统计代码
        _tableStat();
        //初始化统计
        _tableStatInit();
        //ajax加载列表数据
        $.each($('.table-list'),function () {
            var obj = $(this);
            ajax_table_list(obj,'ready');
        })

    });

    //Ajax加载列表信息
    function ajax_table_list(obj,reload,page) {
        var self = obj, self_id = self.attr("data-id"), ajax_url = self.attr("href") || self.attr("data-url"), ajax_map = self.find('#_map'+self_id).val();
        Dolphin.loading();
        self.attr("autocomplete", "off").prop("disabled", true);

        //组装url参数
        if(page)ajax_map += (ajax_map?'&':'')+'page='+page;//分页
        if(ajax_map)ajax_map = (ajax_url.indexOf("?") > -1?'&':'?')+ajax_map;//搜索
        //组装url
        var new_ajax_url = ajax_url+ajax_map;

        // 发送ajax请求
        jQuery.get(new_ajax_url, {}, {}, 'json').success(function(res) {
            Dolphin.loading('hide');

            //渲染列表
            //表头
            var page_title = res.page_title;
            page_title = '<div class="table-title-i"><i class="iconfont mill-lvjuan"></i></div>' + res.page_title;
            self.find('.table-title').html(page_title);
            //按字段搜索
            var _search_area_html;
            if(reload == 'ready' || reload == 'reset'){
                self.find('.form-left').html("");
                self.find('.form-right').html("");
            }
            if(!(res.search == false) && (reload == 'ready' || reload == 'reset')){

                var search_button = '';
                var search_button_html = '';
                if(res.search_button){
                    search_button = 'class="input-group"';
                    search_button_html += '<span class="input-group-btn"><button class="btn btn-default" id="search-submit-btn" type="button">';
                    if(res.search_button === true)search_button_html += '查询';
                    else search_button_html += res.search_button;
                    search_button_html += '</button></span>';
                }

                _search_area_html = '<div class="d-input input-group search-bar">'+
                        '<div class="input-group">'+
                            '<div class="input-group-btn input-search-btn">'+
                                '<button class="btn btn-default search-btn" data-toggle="dropdown" type="button" aria-expanded="false" data-field="'+res.search.field_all+'" data-val="">'+
                                '不限 <span class="caret"></span>'+
                                '</button>'+
                                '<ul class="dropdown-menu">'+
                                    '<li>'+
                                    '<a tabindex="-1" href="javascript:void(0)" data-field="'+res.search.field_all+'">不限</a>'+
                                    '</li>';

                $.each(res.search.fields,function (vk,vo) {
                    _search_area_html += '<li>'+
                                            '<a tabindex="-1" href="javascript:void(0)" data-field="'+vk+'">'+vo+'</a>'+
                                        '</li>';
                });

                _search_area_html += '</ul></div><div '+search_button+'>'+
                '<input type="text" class="layui-input search-input" value="" placeholder="'+res.search.placeholder+'">'+
                        search_button_html+
                        '</div></div></div>';

                self.find('.form-right').append(_search_area_html);
            }

            //分段搜索
            if(!res._search_area_op)res._search_area_op = '';
            self.find('#_o'+self_id).val(res._search_area_op);
            if(res._search_area && (reload == 'ready' || reload == 'reset')){
                $.each(res._search_area,function (vk,vo) {
                    _search_area_html = '';
                    if(vo[0]){
                        if(vo[0] == 'text'){
                            _search_area_html = '<div class="d-input input-group d-input'+res._search_area_layout[vo[1]]+'" data-width="'+res._search_area_layout[vo[1]]+'">'
                                    +'<span class="input-group-addon">'+vo[2]+'</span>'
                                    +'<input class="layui-input" type="'+vo[0]+'" name="'+vo[1]+'" value="'+vo[4]+'" placeholder="'+vo[2]+'">'
                                    +'</div>';
                        }
                        else if(vo[0] == 'select'){
                            var option = '';
                            var selected = '';
                            if(vo[5]){
                                $.each(vo[5],function (k,v) {
                                    if(vo[4] == k)selected = 'selected';
                                    option += '<option value="'+k+'" '+ selected +'>'+v+'</option>';
                                })
                            }
                            _search_area_html = '<div class="d-input input-group d-input'+res._search_area_layout[vo[1]]+'" data-width="'+res._search_area_layout[vo[1]]+'">'
                                    +'<span class="input-group-addon">'+vo[2]+'</span>'
                                    +'<select class="js-select2 layui-input" name="'+vo[1]+'" data-allow-clear="true" data-placeholder="'+vo[2]+'" lay-search="">'
                                    +'<option></option>'
                                    +option
                                    +'</select></div>';
                        }
                        else if(vo[0] == 'daterange'){
                            _search_area_html = '<div class="d-input input-group d-input'+res._search_area_layout[vo[1]]+'"  data-width="'+res._search_area_layout[vo[1]]+'">'
                                    +'<span class="input-group-addon">'+vo[2]+'</span>'
                                    +'<input class="js-daterangepicker layui-input" type="text" id="search_'+self_id+'_'+vo[1]+'" name="'+vo[1]+'" value="'+vo[4]+'" placeholder="'+vo[2]+'" '+vo[5]+'>'
                                    +'</div>';
                        }
                        else if(vo[0] == 'radio'){
                            var radio = '';
                            var checked = '';
                            if(vo[5]){
                                $.each(vo[5],function (k,v) {
                                    if(vo[4] == k)checked = 'checked';
                                    radio += '<label class="css-input css-radio css-radio-primary css-radio-sm push-10-r "><input type="radio" name="'+vo[1]+'" value="'+k+'" '+checked+' ><span></span> '+v+' </label>';
                                })
                            }
                            _search_area_html = '<div class="d-input input-group d-input'+res._search_area_layout[vo[1]]+'" data-width="'+res._search_area_layout[vo[1]]+'">'+radio+'</div>';
                        }

                        if(vo[6] == 'left')self.find('.form-left').append(_search_area_html);
                        else self.find('.form-right').append(_search_area_html);
                    }
                });
            }

            if(_search_area_html){
                _search_area_html = '<div class="input-group" >'
                        +'<button type="submit" class="layui-btn">查询</button>'
                        +'</div><div class="input-group" >'
                        +'<button type="button" class="layui-btn layui-btn-reset" data-href = "'+ajax_url+'">重置</button>'
                        +'</div>';
                self.find('.form-right').append(_search_area_html);
            }

            //列表宽度
            self.css('width',res.builder_width);
            //self.css('width',Math.round(self.width()/$(window).width()*100)+'%');
            //自适应搜索栏宽度
            //var search_width = self.find('form').width();//表单宽度
            var search_width = self.width();//表单宽度
            //如果屏幕宽度-表单到屏幕左侧的距离 < 表单宽度，则限制表单宽度
            //if(($(window).width()-self.offset().left) < search_width)search_width = ($(window).width()-self.offset().left)-200;
            var search_left_width = self.find('.flex-center-left').width();
            var search_right_width = self.find('.flex-center-right').width();
            if((search_left_width+search_right_width) > search_width)self.find('.flex-center-right').css('width',Math.round((search_width-search_left_width)/search_width*100)+'%');

            //顶部按钮
            if(res.top_buttons){
                self.find('.top-buttons').html("");
                $.each(res.top_buttons,function (topk, topv) {
                    self.find('.top-buttons').append(topv);
                });
            }

            //列表头部
            var columns_list = [];
            var column_group = [];
            var columns = [];
            //头部
            //选择器
            if(!res.hide_checkbox && !$.isPlainObject(res.column_group))columns.push({ type:'checkbox',field:'_primary_key_value',align:'center',templet: function(d){return d['_primary_key_value'];}});
            else if(!res.hide_checkbox && res.column_group)column_group.push({ type:'checkbox',field:'_primary_key_value',align:'center',templet: function(d){return d['_primary_key_value'];},rowspan: 2});
            $.each(res.columns,function (columnk, column) {

                //判断是否分组
                var group_rowspan = 0;
                if(column.extra.group && res.column_group[column.extra.group] && $.inArray(column.name,res.column_group[column.extra.group].name) != -1){
                    group_rowspan = res.column_group[column.extra.group].rowspan;
                }

                var new_column = {
                    field: column.name,
                    title: '<div data-laytable="th" class="column-'+column.name+' '+column.class+'">'+column.title+'</div>',
                    align: 'center',
                    //列表内容
                    templet: function(d){
                        if(isJson(column['type']) || column['type'] == '' || column['type'] == 'btn' || column['type'] == 'text')return d[column.name] != null?d[column.name]:'';
                        else return d[column.name+'__'+column['type']] != null?d[column.name+'__'+column['type']]:'';
                    },
                };
                if(res.column_width[column.name])new_column['width'] = res.column_width[column.name];

                //大于1时，则上下合并
                if(group_rowspan > 1){
                    res.column_group[column.extra.group].laydata = new_column;

                }
                else columns.push(new_column);

            });

            //头部分组
            if($.isPlainObject(res.column_group)){
                $.each(res.column_group,function (cgk, cgv) {
                    var new_column = {
                        field: '',
                        title: '<div data-laytable="th" class=" '+cgv.class+'">'+cgv.title+'</div>',
                        align: 'center',
                    };
                    if(cgv.laydata)new_column = cgv.laydata;

                    new_column.colspan = cgv.colspan;
                    new_column.rowspan = cgv.rowspan;
                    column_group.push(new_column);
                });
                columns_list.push(column_group);
            }
            columns_list.push(columns);

            //列表内容
            var rows = res.row_list;

            layui.use(['table'], function(){
                var table = layui.table;

                //渲染JS代码
                self.find(".extra_js").html(res.extra_js);
                //渲染CSS代码
                $("head").append(res.extra_css);
                //重载 reload == 'reset'
                if(reload == 'reload' || reload == 'page'){
                    //渲染表格
                    table.reloadData('#table'+self_id, {
                        data: rows
                    }, false);

                    //渲染顶部按钮
                    //self.find(".layui-table-tool-temp").html(self.find('.top-buttons').html());

                    //渲染分页
                    if(reload == 'reload' || reload == 'reset')tablePage(self_id,res);
                }
                //初始化
                else{
                    var table_options = {
                        id: '#table'+self_id,
                        elem: '#table'+self_id,
                        //toolbar: '#toolbar'+self_id,
                        defaultToolbar: [],//隐藏打印导出
                        cols: columns_list,
                        data: rows,
                        //totalRow: true,//开启合计行  将想要合计的 field 设置  totalRow:true
                        limit: Number.MAX_VALUE, // 数据表格默认全部显示
                        height:'full-420',
                        //height:'570',
                        //height:'655',
                        done: function(res, curr, count) {

                            // 监听单元格点击事件
                            tableDone(self_id);

                        }
                    };
                    // 渲染表格
                    table.render(table_options);
                    //渲染分页
                    tablePage(self_id,res);
                }


                //给表头class赋值
                $.each($("div[data-laytable='th']"),function () {
                    //给表头class赋值
                    $(this).parents('th').attr('class',$(this).attr('class'));
                    $(this).parents('th').removeClass('must');
                });

                //给复选框class赋值
                $(".laytable-cell-checkbox").parents('th,td').addClass('column-checkbox');

                Dolphin.init();
                App.init();
                App.initHelpers(['appear', 'slimscroll', 'magnific-popup', 'table-tools']);
                {notempty name="_js_init"}
                App.initHelpers({$_js_init|raw});
                {/notempty}

            });

        }).fail(function (res) {
            Dolphin.loading('hide');
            Dolphin.notify('服务器内部错误~', 'danger');
            self.attr("autocomplete", "on").prop("disabled", false);
        });
    }

    //渲染分页
    function tablePage(self_id, res) {
        layui.use(['laypage'], function(){
            var laypage = layui.laypage;
            //渲染分页
            if(res.pages){
                var _page_info = res._page_info;

                var laypage_options = {
                    elem: 'table-page'+self_id,
                    count: _page_info.total,
                    limit:_page_info.per_page,
                    theme: '#1E9FFF',
                    prev: '<',
                    next: '>',
                    layout:['prev', 'page', 'next', 'count', 'skip'],
                    jump: function(obj, first){
                        //obj包含了当前分页的所有参数，比如：
                        //console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                        //console.log(obj.limit); //得到每页显示的条数

                        //首次不执行
                        if(!first){
                            var list_obj = $('.table-list[data-id="'+self_id+'"]');
                            //ajax请求
                            ajax_table_list(list_obj,'page',obj.curr);
                        }
                    },
                };
                laypage.render(laypage_options);
            }
            else $('#table-page'+self_id).html("");
        })
    }
    // 监听单元格点击事件
    function tableDone(self_id) {
        var list_obj = $('.table-list[data-id="'+self_id+'"]');
        var table = layui.table;

        // 监听复选框
        table.on('checkbox(___table___'+self_id+')', function (obj) {
            var checkbox_obj = $(obj.tr.selector).find('.laytable-cell-checkbox input[type=checkbox]');
            //console.log(obj); //当前行的一些常用操作集合
            //console.log(obj.checked); //当前是否选中状态
            //console.log(obj.data); //选中行的相关数据
            //console.log(obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one

            //全选
            if(obj.type == 'all'){
                // 遍历表格中的所有行
                table.cache['#table'+self_id].forEach(function(row, index){
                    // row 是当前行的数据对象
                    // index 是当前行的索引
                    // 在这里可以对row进行你需要的操作
                    // console.log(row); // 打印当前行的ID
                });
            }
        });

        //打印
        $(list_obj).find(".quality-print").unbind('click');
        $(list_obj).find(".quality-print").click(function(){
            var obj = $(this).parents(".table-list");
            var table_head = $(obj).find(".layui-table-header table thead").html();
            var table_body = $(obj).find(".layui-table-main tbody").html();
            var table = '<table id="table-print" style="display: none;">'
                    +'<thead>'+table_head+'</thead>'
                    +'<tbody>'+table_body+'</tbody>'
                    +'</table>';
            $("#page-footer").html(table);
            $("#table-print").table2excel({
                // 不被导出的表格行的CSS class类
                exclude: ".layui-table-col-special,.column-checkbox,.text-center,.column-right_button,.js-gallery,.table-reigth-btn,.disable-dch,.hidden-xs,.btn-group",
                // 导出的Excel文档的名称
                name: "Excel Document Name",
                // Excel文件的名称
                filename: list_obj.find('.table-title').text(),
                //文件后缀名
                fileext: ".xls",
                //是否排除导出图片
                exclude_img: false,
                //是否排除导出超链接
                exclude_links: true,
                //是否排除导出输入框中的内容
                exclude_inputs: false
            });
        });

        //选择字段搜索
        var search_input_placeholder = $(list_obj).find('.search-input').attr('placeholder');
        $(list_obj).find('.search-btn').unbind('click');
        $(list_obj).find('.search-btn').click(function () {
            $(list_obj).find('.input-search-btn').addClass('open');
            return false;
        });
        //关闭弹出框
        $('body').bind("click",function(e){
            if($(e.target).closest(".search-btn").length == 0)$(list_obj).find('.input-search-btn').removeClass('open');
        });
        $(list_obj).find('.search-bar .dropdown-menu a').unbind('click');
        $(list_obj).find('.search-bar .dropdown-menu a').click(function () {
            //选择字段
            var field = $(this).data('field') || '';
            $(list_obj).find('.search-btn').attr('data-field',field);
            $(list_obj).find('.search-btn').html($(this).text() + ' <span class="caret"></span>');
            if ($(this).text() === '不限') {
                $(list_obj).find('.search-input').attr('placeholder', search_input_placeholder);
            } else {
                $(list_obj).find('.search-input').attr('placeholder', '请输入'+$(this).text());
            }
            $(list_obj).find('.input-search-btn').removeClass('open');
        });
        $(list_obj).find('.search-input').unbind('keyup');
        $(list_obj).find('.search-input').keyup(function () {
            //搜索值
            $(list_obj).find('.search-btn').attr('data-val',$(this).val());
        });

        //点击查看并刷新右侧列表数据
        $(list_obj).find('.jump_right').unbind('click');
        $(list_obj).find('.jump_right').click(function () {
            var list_obj_right = list_obj.siblings('.table-list');

            var url = list_obj_right.find('form').attr('action');
            var param = $(this).attr("data-param");
            var new_url = url+"?"+param;

            $(list_obj_right).attr("data-url",new_url);

            // 重置右侧搜索
            list_obj_right.find('#_map'+$(list_obj_right).attr("data-id")).val("");
            ajax_table_list(list_obj_right,'reset');

        });

        // 搜索区域
        $(list_obj).find('form').unbind('submit');
        $(list_obj).find('form').submit(function () {
            var items = $(list_obj).find('form').serializeArray();
            var op  = $(list_obj).find('#_o'+self_id).val();
            var str = [];
            $.each(items, function (index, e) {
                str.push(e.name + '=' + e.value)
            });
            str = str.join('|');
            var map = '_s='+str+'&_o='+op;

            //如果字段搜索存在，则拼接
            if(search_input_placeholder){
                var search_field = $(list_obj).find('.search-btn').attr('data-field');
                var search_val = $(list_obj).find('.search-btn').attr('data-val');
                if(search_val)map += '&search_field='+search_field+'&keyword='+search_val;
            }

            list_obj.find('#_map'+self_id).val(map);

            ajax_table_list(list_obj,'reload');
            return false;
        });

        // 重置搜索
        $(list_obj).find('.layui-btn-reset').unbind('click');
        $(list_obj).find('.layui-btn-reset').click(function () {
            // 重置表单链接
            $(list_obj).attr("data-url",list_obj.find('form').attr('action'));
            // 重置搜索参数
            list_obj.find('#_map'+self_id).val("");

            ajax_table_list(list_obj,'reset');
            return false;
        });

        //弹出框显示页面
        //此事件已作废
        //跟dolphin.js的js-get方法冲突，以迁移至dolphin.js的pop方法
        $(list_obj).delegate('a.pop').unbind('click');
        $(list_obj).delegate('a.pop', 'click', function () {

            var $url   = $(this).attr('href');
            var $title = $(this).attr('title') || $(this).data('original-title');
            var $layer = $(this).data('layer');

            // 把当前页面的过虑参数带到弹出POP中
            var locationUrlSearch = location.search.substring(1);
            if (locationUrlSearch) {
                if ($url.indexOf('?') !== -1) {
                    $url += '&' + locationUrlSearch;
                } else {
                    $url += '?' + locationUrlSearch;
                }
            }

            // 是否需要获取表格数据
            if ($(this).hasClass('js-get')) {
                var target_form = $(this).attr("target-form");
                var form        = jQuery('form[name=' + target_form + ']');
                var form_data   = form.serialize() || [];

                if (form.length === 0) {
                    form = $(list_obj).find('input[name=layTableCheckbox][type=checkbox]:checked').parents("td[data-field='_primary_key_value']");
                    form.each(function () {
                        form_data.push($(this).data('content'));
                    });
                    form_data = form_data.join(',');
                }

                if (form_data === '') {
                    Dolphin.notify('请选择要操作的数据', 'warning');
                    return false;
                }

                if ($url.indexOf('?') !== -1) {
                    $url += '&' + target_form + '=' + form_data;
                } else {
                    $url += '?' + target_form + '=' + form_data;
                }
            }
            // 是否需要获取表格数据
            if ($(this).hasClass('dch-js-get')) {
                var target_form = $(this).attr("target-form");
                var form        = $('form[name=' + target_form + ']');
                var form_data   = form.serialize() || [];

                if (form.length === 0) {
                    form = $(list_obj).find('input[name=layTableCheckbox][type=checkbox]:checked').parents("td[data-field='_primary_key_value']");
                    form.each(function () {
                        form_data.push($(this).data('content'));
                    });
                    form_data = form_data.join(',');
                }

                if ($url.indexOf('?') !== -1) {
                    $url += '&' + target_form + '=' + form_data;
                } else {
                    $url += '?' + target_form + '=' + form_data;
                }
            }

            var $options = {
                title: $title,
                content: $url,
                shadeClose:true
            };

            // 处理各种回调方法
            dolphin.layer.success = dolphin.layer.success ? window[dolphin.layer.success] : null;
            dolphin.layer.yes     = dolphin.layer.yes ? window[dolphin.layer.yes] : null;
            dolphin.layer.cancel  = dolphin.layer.cancel ? window[dolphin.layer.cancel] : null;
            dolphin.layer.end     = dolphin.layer.end ? window[dolphin.layer.end] : null;
            dolphin.layer.full    = dolphin.layer.full ? window[dolphin.layer.full] : null;
            dolphin.layer.min     = dolphin.layer.min ? window[dolphin.layer.min] : null;
            dolphin.layer.max     = dolphin.layer.max ? window[dolphin.layer.max] : null;
            dolphin.layer.restore = dolphin.layer.restore ? window[dolphin.layer.restore] : null;

            if ($layer !== undefined) {
                // 处理各种回调方法
                $layer.success = $layer.success ? window[$layer.success] : dolphin.layer.success;
                $layer.yes     = $layer.yes ? window[$layer.yes] : dolphin.layer.yes;
                $layer.cancel  = $layer.cancel ? window[$layer.cancel] : dolphin.layer.cancel;
                $layer.end     = $layer.end ? window[$layer.end] : dolphin.layer.end;
                $layer.full    = $layer.full ? window[$layer.full] : dolphin.layer.full;
                $layer.min     = $layer.min ? window[$layer.min] : dolphin.layer.min;
                $layer.max     = $layer.max ? window[$layer.max] : dolphin.layer.max;
                $layer.restore = $layer.restore ? window[$layer.restore] : dolphin.layer.restore;

                $.extend($options, dolphin.layer, $layer);
            } else {
                $.extend($options, dolphin.layer);
            }

            if ($options.cancel === null && (typeof window.layer_cancel === "function")) {
                $options.cancel = window.layer_cancel;
            }
            if ($options.success === null && (typeof window.layer_success === "function")) {
                $options.success = window.layer_success;
            }
            if ($options.yes === null && (typeof window.layer_yes === "function")) {
                $options.yes = window.layer_yes;
            }
            if ($options.end === null && (typeof window.layer_end === "function")) {
                $options.end = window.layer_end;
            }
            if ($options.full === null && (typeof window.layer_full === "function")) {
                $options.full = window.layer_full;
            }
            if ($options.min === null && (typeof window.layer_min === "function")) {
                $options.min = window.layer_min;
            }
            if ($options.max === null && (typeof window.layer_max === "function")) {
                $options.max = window.layer_max;
            }
            if ($options.restore === null && (typeof window.layer_restore === "function")) {
                $options.restore = window.layer_restore;
            }

            $options.success = function(layero, index){
                //layer.iframeAuto(index);

                var iframeIndex = layer.getChildFrame('body', index); // 获取子页面的body
                //获取子页面高度
                var iframeHeight = $(iframeIndex)[0].scrollHeight + 80;
                //给子页面设置浮动
                iframeIndex.find('.row').css('overflow-x','scroll');

                //浏览器页面高度
                var bodyHeight = $(window).height();

                if(iframeHeight <= bodyHeight){
                    layer.style(index, {
                        // 重新居中的样式
                        top: (layui.$(window).height() - iframeHeight) / 2,
                        height: iframeHeight
                    })
                }

            };

            layer.open($options);
            return false;
        });

        // 开关
        $(list_obj).find('.switch,.switch2').unbind('click');
        $(list_obj).find('.switch,.switch2').click(function () {
            var $switch = $(this).find('input:checkbox');
            var checked = $switch.prop('checked');
            if($(this).hasClass('switch2'))checked = !checked;//switch2：反向取值
            var $data = {
                value: checked,
                _t: $switch.data('table') || '',
                name: $switch.data('field') || '',
                type: 'switch',
                pk: $switch.data('id') || ''
            };

            // 发送ajax请求
            Dolphin.loading();
            $.post(dolphin.quick_edit_url, $data).success(function(res) {
                Dolphin.loading('hide');
                if (res.code) {
                    Dolphin.notify(res.msg, 'success');
                } else {
                    Dolphin.notify(res.msg, 'danger');
                    $switch.prop('checked', !$switch.prop('checked'));
                    return false;
                }
            }).fail(function (res) {
                Dolphin.loading('hide');
                Dolphin.notify($(res.responseText).find('h1').text() || '服务器内部错误~', 'danger');
            });
        });

        //额外的js点击事件
        for (var name in layui_func) {
            if (typeof layui_func[name] === "function") {
                layui_func[name]();
            }
        }

        //处理点击更多后，按钮事件失效的问题 layui-table-grid-down
        $(document).off('mousedown', '.layui-table-grid-down').on('mousedown', '.layui-table-grid-down', function (event) {
            table._tableTrCurr = $(this).closest('td');
        });
        //处理点击更多后，按钮事件失效的问题 layui-table-grid-down
        $(document).off('click', '.layui-table-tips-main [_tag]').on('click', '.layui-table-tips-main [_tag]', function (event) {
            var elem = $(this);
            var tableTrCurr = table._tableTrCurr;
            if (!tableTrCurr)return;
            var layerIndex = elem.closest('.layui-table-tips').attr('times');

            // 关闭当前这个显示更多的tip
            layer.close(layerIndex);
            table._tableTrCurr.find('[_tag="' + elem.attr('_tag') + '"]').first().click();
            return false;
        });


    }

    //统计代码，只加载一次
    function _tableStat(){
        for (var name in stat_func) {
            if (typeof stat_func[name] === "function") {
                stat_func[name]();
            }
        }
    }
    //初始化统计
    function _tableStatInit(){
        for (var name in stat_init_func) {
            if (typeof stat_init_func[name] === "function") {
                stat_init_func[name]();
            }
        }
    }
    //判断是不是JSON
    function isJson(obj){
        return typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length;
    }
    //判断是不是HTML编码
    function isHtml(input) {
        return /<[a-z]+\d?(\s+[\w-]+=("[^"]*"|'[^']*'))*\s*\/?>|&#?\w+;/i.test(input);
    }

</script>
{volist name="js_list" id="vo"}
<script src="{$vo}?v={:config('asset_version')}"></script>
{/volist}

{// 额外JS代码 }
{$extra_js|raw|default=''}
{/block}

<script>
    $(document).off('mousedown', '.layui-table-grid-down')
            .on('mousedown', '.layui-table-grid-down', function (event) {
                table._tableTrCurr = $(this).closest('td');
                //console.log($('.layui-table-tips-main').html());
                //alert(1);
            });
</script>